package com.volkanic.controller;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.volkanic.views.menu.MenuView;

/**
 * Created by Lucas on 24/07/2014.
 */
public class SharedController {

    /**
     * Enumeration of the state of the game
     */
    public static enum StageState {
        MENU,
        WORLD_SELECTION,
        HIGHSCORE,
        LEVEL,
        MULTIPALYER,
        EXIT
    }

    /**
     * The libGdx Game
     */
    private Game _game;
    /**
     * The current state of the game
     */
    private StageState _currentState;
    /**
     * Determine if the screen have been set
     */
    private boolean screenIsSet;

    /**
     * Create a new instance of the class SharedController
     * @param game The libGdx game
     * @param state The state of the controller
     */
    public SharedController(Game game, StageState state){
        screenIsSet = false;
        _game = game;
        changeStateTo(state);
    }

    /**
     * Change the current state of the game
     * @param state the new state of the game
     */
    public void changeStateTo(StageState state){
        this.disposeScreen();
        _currentState = state;
        this.changeStage();
        screenIsSet = true;
    }

    /**
     * Dispose the element included in the screen
     */
    private void disposeScreen(){
        if (screenIsSet){
            _game.getScreen().dispose();
        }
    }

    /**
     * Change the current stage
     */
    public void changeStage(){
        switch(_currentState){
            case MENU:
                _game.setScreen(new MenuView(_game, this, StageState.MENU));
                break;
            case WORLD_SELECTION:
                break;
            case HIGHSCORE:
                break;
            case LEVEL:
                break;
            case MULTIPALYER:
                break;
            case EXIT:
                _game.dispose();
                Gdx.app.exit();
                break;
            default:
                break;
        }

    }
}
